package edu.pku.sei.act.ctrl.command;

import org.eclipse.gef.commands.Command;
import edu.pku.sei.act.model.mote.Data;
import edu.pku.sei.act.model.mote.Mote;

public class DeleteDataCommand extends Command{
	
	private Mote mote;
	private Data data;

	public DeleteDataCommand(Data data) {
		super("Delete Data");
		this.data = data;
		if (data.getContainer() instanceof Mote) {
			mote = (Mote) data.getContainer();
		}
	}

	public boolean canExecute() {
		return data != null &&  mote != null;
	}

	public void execute() {
		if (mote != null) {
			mote.setData(null);
		}
		data.setContainer(null);
	}

	public void undo() {
		if (mote != null) {
			data.setContainer(mote);
			mote.setData(data);
		}
	}

}
